<template>
  <div class="app-container" :loading="submitLoading">
    <div class="filter-container">
      <div style="align-items: center; display: flex;justify-content: flex-start;">
        <div class='header_title'>
          <el-input style="width:202px"
            v-model="req_xin_xi.keyword"
            placeholder="搜索关键字"
          ></el-input>
          <div class="block" style="width:205px">
            <el-date-picker
              v-model="req_xin_xi.search_time"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="yyyy-MM-dd HH:mm:ss"
              align="center"
              value-format=""
              clearable
            >
            </el-date-picker>
          </div>
          <el-select
            style="width:150px"
            v-model="fuze_name"
            multiple
            filterable
            remote
            reserve-keyword
            placeholder="搜索负责人"
            :remote-method="remoteMethod"
            :loading="loading"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <el-button type="primary" icon="el-icon-search" @click="searchList()">
          搜索
        </el-button>
      </div>
    </div>
    <!-- 列表-->
    <el-table :data="list" v-loading="listLoading" border style="width: 100%">
      <el-table-column label="名次" align="center">
        <template slot-scope="scope">
          <span class="link-type" @click="list_detail(scope)">{{
            scope.row.position
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="年度计划回款量" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.num }}</span>
        </template>
      </el-table-column>
       <el-table-column label="已回业务量折后金额合计" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.count }}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="详情" :visible.sync="dialogVisible" width="50%" center>
      <div>
        <el-form
          ref="diary_details"
          :model="diary_details"
          label-width="80px"
          style="text-align: left"
        >
          <el-form-item label="标题:">
            <div>{{ diary_details.title }}</div>
          </el-form-item>
          <el-form-item label="内容:">
            {{ diary_details.content }}
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 分页-->
    <div class="fenye">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="page_limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page_count"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import {
  notice_list,
  notice_del,
  notice_add,
  notice_detail,
  notice_top,
  notice_edit,
} from "@/api/setup/setup_notice";
export default {
  name: "huikuan_rank",
  data() {
    return {
      fuze_name:'',
      req_xin_xi: {
        search_time: "",
        keyword:''
      },
      loading:false,
      options:[],
      ruleForm: {
        title: "",
        content: "",
        sort: 0,
        is_top: false,
      },
      rules: {
        title: [
          {
            required: true,
            message: "请输入标题",
            trigger: "blur",
          },
        ],
      },
      listLoading: 0,
      submitLoading: false,
      popup_edit_show: false,
      popup_add_show: false,
      diary_details: {},
      dialogVisible: false,
      // jia_content: "",
      // jia_title: "",
      list: [
        {id:1,position:1,name:'王萌',num:100,count:100},
        {id:2,position:2,name:'王萌',num:100,count:100},
        {id:3,position:3,name:'王萌',num:100,count:100},
        {id:4,position:4,name:'王萌',num:100,count:100}
      ],
      listQuery: {
        key_word: "",
        searchTime: [],
      },
      // tableKey: 1,
      currentPage: 1,
      page_count: 0,
      page_limit: 10,
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  created() {

  },
  mounted() {},
  methods: {
    remoteMethod(){

    },
  
    //搜索事件
    searchList() {
      this.getList(1, this.page_limit, this.listQuery);
    },
    //每页几条数据
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.page_limit = val;
      this.getList(1, val, this.listQuery);
    },
    //跳转到
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.getList(val, this.page_limit, this.listQuery);
    },
    //新增数据提交
    submit_add() {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          this.submitLoading = true;
          notice_add(
            this.ruleForm.title,
            this.ruleForm.content,
            this.ruleForm.is_top,
            this.ruleForm.sort
          )
            .then((res) => {
              if (res.code == 200) {
                this.$message({
                  message: res.msg,
                  type: "success",
                });
                this.getList(this.currentPage, this.page_limit, this.listQuery);
                this.popup_add_show = false;
                this.submitLoading = false;
                this.ruleForm.title = "";
                this.ruleForm.content = "";
                this.ruleForm.sort = 0;
                this.ruleForm.is_top = false;
              }
            })
            .catch(() => {
              this.submitLoading = false;
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    list_del(val) {
      let that = this;
      notice_del(val.row.id).then((res) => {
        console.log(res);
        if (res.code == 200) {
          this.getList(this.currentPage, this.page_limit, this.listQuery);
        }
      });
    },
    list_detail(val) {
      let that = this;
      notice_detail(val.row.id).then((res) => {
        console.log(res);
        if (res.code == 200) {
          that.dialogVisible = true;
          that.diary_details = res.data;
        }
      });
    },
    // 修改是否置顶 istop 1,0
    changeIsTop(val, isTop) {
      notice_top(val.row.id, isTop).then((res) => {
        console.log(res);
        if (res.code == 200) {
          this.$message({
            message: res.msg,
            type: "success",
          });
          this.getList(this.currentPage, this.page_limit, this.listQuery);
        }
      });
    },
    add(val) {
      this.ruleForm.is_top = false;
      this.popup_add_show = true;
    },
    edit(val) {
      this.diary_details = val;
      this.ruleForm.is_top = val.is_top ? true : false;
      this.popup_edit_show = true;
    },
    submit_edit() {
      let that = this;
      this.$refs.diary_details.validate((valid) => {
        if (valid) {
          console.log(that.diary_details, "fff");
          that.diary_details.is_top = that.diary_details.is_top ? 1 : 0;
          that.submitLoading = true;
          notice_edit(
            that.diary_details.id,
            that.ruleForm.is_top,
            that.diary_details.title,
            that.diary_details.content,
            that.diary_details.sort
          ).then((res) => {
            if (res.code == 200) {
              that.popup_edit_show = false;
              that.submitLoading = false;
              that.getList(this.currentPage, this.page_limit, this.listQuery);
            }
          });
        } else {
          console.log("输入框错误");
        }
      });
    },
  },
};
</script>
<style type="text/css">
.sortable-ghost {
  opacity: 0.8;
  color: #fff !important;
  background: #42b983 !important;
}

.fenye {
  padding: 20px 0px;
}

.el-range-editor.el-input__inner {
  width: 205px !important;
  padding: 3px 3px !important;
}

.el-input__icon {
  display: none !important;
}
.header_title{
  display: flex;
  width: 620px;
  justify-content: flex-start;
}
</style>
